%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Filename:      graduation_design.tex
% Author:        Junwei Wang(wakemecn@gmail.com)
% Last Modified: 2012-05-06 11:07
% Description:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[a4paper,12pt,oneside,openany]{book}
\usepackage{ctex}
\usepackage[top=1in,bottom=1in,left=1.25in,right=1.25in]{geometry}
\usepackage{graphicx}
\usepackage{ulem}
\usepackage{amsfonts,amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[bf,small,center,indentafter,pagestyles]{titlesec}
% redefine some name
\renewcommand{\chaptername}{第\chinese{chapter}章}
\renewcommand{\bibname}{参考文献}
% redefine the chapter section
\titleclass{\chapter}{straight}
\titleformat{\chapter}[hang]
{\centering\zihao{-3}\bfseries}{第\chinese{chapter}章}{1em}{}
\titleformat{\section}
{\normalfont\zihao{4}\bfseries}{\thesection}{11pt}{\large}
% define pagehead style
\newpagestyle{firstpage}{
}
\newpagestyle{abstract}{
    \sethead{}{}{\kaishu\small\hfill 摘\qquad 要\hfill \thepage}
    \setfoot{}{}{}\headrule
}
\newpagestyle{tableofcontent}{
    \sethead{}{}{\kaishu\small\hfill 目\qquad 录 \hfill \thepage}
    \setfoot{}{}{}\headrule
}
\newpagestyle{main}{
   \sethead{}{}{\kaishu\small\hfill \chaptername\quad\chaptertitle\hfill\thepage}
   \setfoot{}{}{}\headrule
}
%%
\usepackage{titletoc}
\usepackage[titletoc]{appendix}
%定义目录格式
\titlecontents{chapter}[0em]{\normalsize}
{\thecontentslabel\hspace*{1em}}{\hspace*{-2.3em}}
{\titlerule*[0.8pc]{.}\contentspage}

\titlecontents{section}[0em]{\normalsize}
{\thecontentslabel\hspace*{1em}}{\hspace*{-2.3em}}
{\titlerule*[0.8pc]{.}\contentspage}

\titlecontents{subsection}[0em] {\normalsize}
{\thecontentslabel\hspace*{1em}}{\hspace*{-2.3em}}
{\titlerule*[0.8pc]{.}\contentspage}
%%%%%%%%%%%%%code style%%%%%%%%%%
\usepackage{xcolor}
\renewcommand{\ttdefault}{phv}
\usepackage{listings}
\renewcommand{\lstlistingname}{代码}
\lstset{
         basicstyle=\footnotesize\ttfamily, % Standardschrift
         %numbers=left,               % Ort der Zeilennummern
         numberstyle=\tiny,          % Stil der Zeilennummern
         %stepnumber=2,               % Abstand zwischen den Zeilennummern
         numbersep=5pt,              % Abstand der Nummern zum Text
         tabsize=2,                  % Groesse von Tabs
         extendedchars=true,         %
         breaklines=true,            % Zeilen werden Umgebrochen
         keywordstyle=\color{red},
            frame=b,         
         stringstyle=\color{white}\ttfamily, % Farbe der String
         showspaces=false,           % Leerzeichen anzeigen ?
         showtabs=false,             % Tabs anzeigen ?
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,
%        backgroundcolor=\color{lightgray},
         showstringspaces=false      % Leerzeichen in Strings anzeigen ?       
}
\lstloadlanguages{% Check Dokumentation for further languages ...
         %[Visual]Basic
         %Pascal
         %C
         %C++
         %XML
         %HTML
         Java
}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,justification=raggedright,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={sf,bf,footnotesize}}
%%%%%%%%%%%%%code style%%%%%%%%%%
% 取消中文连字符与文字间的空格
\normalspacedchars{-}
% 定义"defination"环境
\newtheorem{Definition}{定义}
\begin{document}
% titlepage
\frontmatter
\pagestyle{firstpage}
\include{titlepage}
% abstract
\pagestyle{abstract}
\include{abstract}
% contents
\pagestyle{tableofcontent}
\renewcommand{\contentsname}{目\quad 录}
\tableofcontents
% 绪论 
\mainmatter
\pagestyle{main}
\include{introduction}
% 相关工作
\include{related_work}
% 背景 
\include{background}
% 构造
\include{construction}
% 实现
\include{implementation}
% 附录
\include{appendix}

\addcontentsline{toc}{chapter}{\qquad 参考文献}
\bibliographystyle{plain}
\bibliography{graduation_design}
\end{document}
